package com.vn.controller;

import java.util.Date;

import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.portlet.bind.annotation.ResourceMapping;

import com.vn.entity.Building;
import com.vn.entity.BuildingType;
import com.vn.entity.ChargeRegister;
import com.vn.entity.ChargeRegisterPayment;
import com.vn.entity.ChargeRegisterPaymentPK;
import com.vn.entity.Compartment;
import com.vn.entity.CompartmentType;
import com.vn.entity.Customer;
import com.vn.entity.Interest;
import com.vn.entity.Land;
import com.vn.entity.Location;
import com.vn.entity.PaymentInstallment;
import com.vn.entity.PaymentInstallmentPK;
import com.vn.entity.PaymentMode;
import com.vn.entity.PurchaseContract;
import com.vn.entity.Storage;
import com.vn.entity.StoreDetail;
import com.vn.service.MyService;



@Controller
public class TestImage {
	
	@Autowired
	private MyService myService;
	
	@RequestMapping(value="/insert_storage",method = RequestMethod.GET)
	public String insertStorage()
	{
		Storage storage=new Storage();
		storage.setFolderName("MyFolder");
		myService.addStorage(storage);
		return "success";
	}
	
	@RequestMapping(value="/insert_store_detail",method = RequestMethod.GET)
	public String insertImage()
	{
		Storage storage=myService.getStorageByName("MyFolder");
		
		
		StoreDetail storeDetail=new StoreDetail();
		storeDetail.setStorage(storage);
		storeDetail.setFileName("tan.jsp");
		storeDetail.setPath("c:/tan/tan.jsp");
		storeDetail.setDescription("Day la Demo");
		storeDetail.setType((short)0);
		storeDetail.setValid(true);
		
		myService.addStorageDetail(storeDetail);
		return "success";
		
		
	}
	
	@RequestMapping(value="/insert_location",method = RequestMethod.GET)
	public String insertLocation()
	{
		Storage storage=myService.getStorageByName("MyFolder");
		
		
		Location loc=new Location();
		loc.setStorage(storage);
		loc.setAddress("sdfasd");
		
		myService.addLocation(loc);
		return "success";
		
		
	}
	
	@RequestMapping(value="/get_location_folder",method = RequestMethod.GET)
	@ResponseBody
	public String getLocation()
	{
		Location loc=myService.getLocationById(1);
		return loc.getStorage().getFolderName();
		
		
	}
	
	@RequestMapping(value="/add_land",method = RequestMethod.GET)
	public String addLand()
	{
		Storage storage=myService.getStorageByName("MyFolder");
		Location location=myService.getLocationById(1);
		Land land=new Land("3/53 hoa loang"
				, "khu cu xa bac sai gon"
				,222.4
				, new Date(2011,11,22)
				,location
				, "xay khu mua sam"
				, storage
				, "chua co gi"
				, false);
		myService.addLand(land);
		return "success";
	}
	
	@RequestMapping(value="/add_building_type",method = RequestMethod.GET)
	public String addBuildingType()
	{
		BuildingType buildingType=new BuildingType("AAA");
		myService.addBuildingType(buildingType);
		return "success";
	}
	
	@RequestMapping(value="/add_building",method = RequestMethod.GET)
	public String addBuilding()
	{
		Land land=myService.getLandById(3);
		BuildingType buildingType=myService.getBuildingTypeById((short)1);
		Storage storage=myService.getStorageByName("MyFolder");
		short a=0;
		Building building=new Building("AAA"
				, land
				, buildingType
				, "Toa Nha aptech"
				, 33
				, 22
				, a
				, new Date(2011,11,11)
				, new Date(2011,11,11)
				, new Date(2011,11,11)
				, storage
				, "No log"
				, false);
		myService.addBuilding(building);
		return "success";
	}
	
	@RequestMapping(value="/add_compartmentType",method=RequestMethod.GET)
	public String addCompartmentType()
	{
		CompartmentType ct=new CompartmentType("sdfdsf");
		myService.addCompartmentType(ct);
		return "success";
	}
	
	
	@RequestMapping(value="/add_compartment",method = RequestMethod.GET)
	public String addCompartment()
	{
		Building building=myService.getBuildingById("AAA");
		CompartmentType compartmentType=myService.getCompartmentTypeById(1);
		Storage storage=myService.getStorageByName("MyFolder");
		Compartment compartment=new Compartment("11111111", building, compartmentType, 2, (double)2.333, (short)0, new Date(2001,1,1),(double) 45.4, storage, false, false);
		myService.addCompartment(compartment);
		return "success";
	}
	
	@RequestMapping(value="/add_payment_mode",method = RequestMethod.GET)
	public String addPaymentMode()
	{
		PaymentMode paymentMode=new PaymentMode((short)1, (short)3);
		myService.addPaymentMode(paymentMode);
		return "success";
	}
	
	@RequestMapping(value="/add_interest",method = RequestMethod.GET)
	public String addInterest()
	{
		PaymentMode paymentMode=myService.getPaymentModeById(1);
		Interest interest=new Interest(paymentMode, new Date(), 22.2);
		myService.addInterest(interest);
		return "success";
	}
	
	@RequestMapping(value="/add_customer",method = RequestMethod.GET)
	public String addCustomer()
	{
		Storage storage=myService.getStorageByName("MyFolder");
		Customer customer=new Customer("343433333", "Nguyen Van Tan", (short)1, new Date(), "Binh Duong", "Binh Duong", "Binh Duong",new Date(), "2/33 Hoa Long Binh Duong", "033434343", "dfdsf@gmail.com", storage);
		myService.addCustomer(customer);
		return "success";
	}
	
	@RequestMapping(value="/add_charge_register",method=RequestMethod.GET)
	public String addChargeRegister()
	{
		ChargeRegister chargeRegister=new ChargeRegister(22.3, "new cost");
		myService.addChargeRegister(chargeRegister);
		return "success";
	}
	
	@RequestMapping(value="/add_purchase_contract",method=RequestMethod.GET)
	public String addPurchaseContract()
	{
		Customer customer=myService.getCustomerById("343433333");
		Compartment compartment=myService.getCompartmentById("11111111");
		PaymentMode paymentMode=myService.getPaymentModeById(1);
		Storage storage=myService.getStorageByName("MyFolder");
		PurchaseContract pur=new PurchaseContract(new Date(), customer, compartment, 33.4, paymentMode, 33.4, (short)0, (short)0, storage, "dfd");
		myService.addPurchaseContract(pur);
		return "success";
	}
	
	@RequestMapping(value="/add_payment_installment",method=RequestMethod.GET)
	public String addPaymentInstallment()
	{
		PaymentInstallmentPK pk=new PaymentInstallmentPK(1, new Date());
		PurchaseContract purchaseContract=myService.getPurchaseContractById(1);
		PaymentInstallment paymentInstallment=new PaymentInstallment(pk, purchaseContract, new Date(), 222.3, (short)0, "no log");
		myService.addPaymentInstallment(paymentInstallment);
		return "success";
	}
	
	@RequestMapping(value="/add_crp",method=RequestMethod.GET)
	public String addCrb()
	{
		ChargeRegister chargeRegister=myService.getChargeRegisterById(1);
		PurchaseContract purchaseContract=myService.getPurchaseContractById(1);
		ChargeRegisterPaymentPK pk=new ChargeRegisterPaymentPK(purchaseContract.getId(), chargeRegister.getId());
		ChargeRegisterPayment chargeRegisterPayment=new ChargeRegisterPayment(pk, purchaseContract, chargeRegister, new Date());
		myService.addChargeRegisterPayment(chargeRegisterPayment);
		return "success";
	}
}
